package main

// import (

// 	"github.com/astaxie/beego"
// )

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego/plugins/cors"
	// "github.com/astaxie/beego/plugins/auth"
	_ "github.com/mattn/go-sqlite3"
	// "hapi/models"
	_ "hapi/routers"
	// _ "minerva/routers"
)

func init() {
	fmt.Printf("Calling main.init")
	orm.RegisterDriver("sqlite3", orm.DRSqlite)
	orm.RegisterDataBase("default", "sqlite3", "hitdic.db")
	name := "default"
	force := false
	verbose := true
	err := orm.RunSyncdb(name, force, verbose)
	if err != nil {
		fmt.Println(err)
	}

	// orm.RegisterModel(new(models.User), new(models.Profile))
	fmt.Printf("Try to add some new users")
	// models.AddUser(models.User{Username: "abc"})
	// models.AddUser(models.User{Username: "abcd"})
	// models.AddUser(models.User{Username: "abce"})

	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin"},
		AllowCredentials: true,
	}))
}

func main() {
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.Run()
}
